﻿/***********************
*DESC:表格动态增加删除行
*Author:wff 
*Date:2015-05-5
*
************************/

; (function ($) {
    $.fn.tables = function (option) {
        //定义默认参数
        var defaults = {
            name: "", //grid id
            deleteName: this, //delete object
            tbResult: ""
        };
        //整合传入参数
        var opt = $.extend({}, defaults, option);

    };

    //增加行
    $.fn.tables.addRow = function (gridId) {
        var tbRow = $("#" + gridId).find("tr").eq(1).html();
        var num = $("#" + gridId + " tr").length;
		
		$("#" + gridId).append("<tr id=" + num + ">" + tbRow + "</tr>");
        $("#" + gridId).find("tr").last().find("td").last().children().removeAttr("name").attr("value", "");
    };

    //删除行 
    //参数obj  当前对象
    $.fn.tables.deleteRow = function (obj) {
        var $this = $(obj);
		if ($this.parents("tbody").find("tr").length < 1) {
																	   
            return false;
        }
		/*第一行删除即为清空第一行数据操作*/
		if ($this.parents("tbody").find("tr").length == 1) {
			
			
				$this.parents("tr").find("td").each(function () {
					var $child = $(this).children();
					switch ($child.attr("type")) {
									case "text":
										
										$child.val("");
										break;
									
									case "a":
									case "button":
										$child.attr("value", val);
										break;
									default:
								}
				});	
				
			return false;
		}
        $this.parents("tr").remove();
    };

    //取表格所有数据
    //返回值为一个数组，数组内每一个元素对应一行内的数据;
    $.fn.tables.getResult = function (gridId) {

        var resultArray = new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {
			var isNull = "";
            var trResult = "{";

            $(this).find("td").each(function () {
                var $child = $(this).children();

                if ($child.length > 1) {
                   
                } else {
                    //td 下只有一个元素
                    switch ($child.attr("type")) {
                        case "text":

                            trResult += '"' + $child.attr("name") + '"' + ":" + '"' + $child.val() + '"' + ",";
							isNull += $child.val();
                            break;
                        case "select":

                            trResult += '"' + $child.attr("name") + '"' + ":" + '"' + $child.find("option:selected").val() + '"' + ",";
                            break;
                        case "checkbox":
                            if ($(this).attr("checked") === "checked") {
                                trResult += '"' + $child.attr("name") + '"' + ":" + '"' + $child.val() + '"' + ",";
                            } else {
                                trResult += '"' + $child.attr("name") + '"' + ":0" + '"' + ",";
                            }
                            break;
                        case "radio":
                            if ($(this).attr("checked") === "checked") {
                                trResult += '"' + $child.attr("propertys") + '"' + ":" + '"' + $child.val() + '"' + ",";
                            } else {
                                trResult += '"' + $child.attr("propertys") + '"' + ":0" + '"' + ",";
                            }
                            break;


                        default:
                    }
                }
            });

            trResult = trResult.substring(0, trResult.length - 1);
			if(isNull == ""){
				console.log("Tr is Null");
			}
			else
				resultArray.push(trResult + "}");

        });

        return resultArray;
    };

    //验证行
    $.fn.tables.validateRow = function (gridId) {

        //是否验证通过
        var isPass = true;
		 $("#" + gridId).find("tr").slice(1).each(function () {
			$(this).find("td").each(function () {
					$('.text-error').remove();
					$(this).children().removeClass("error");
			});
		});
        $("#" + gridId).find("tr").slice(1).each(function () {

            $(this).find("td").each(function () {				              
                var $this = $(this).children();
                var validate = $this.attr("validate");
				if(validate == undefined || validate == '' ){
					return true;
				}
		 		var rules = validate.split("|");
		 		for (var i = 0,ruleLength = rules.length; i < ruleLength; i++) {
					var method = rules[i];
					var ruleRegex = /^(.+?)\[(.+)\]$/;
					var parts = ruleRegex.exec(method);
					var  param = null;
					if (parts) {
						method = parts[1];
						param = parts[2];
					}
					switch (method) {
						case "required":
							var errorMsg = "此字段为必填项!";
							if ($.trim($this.val()) == "" || $this.val() == "" || $this.val() == "null" || $this.val() == null) {
                                    isPass = false;
									
										$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							break;
						case "integer":
							var errorMsg = "此字段必须为整数!";
							var  integerRegex = /^\-?[0-9]+$/;
							
							var keyVal= $this.val();  
							if(keyVal==undefined || keyVal=="" || keyVal==null || keyVal.length==0){
								console.log("nll");
							}
							else{
								
								if(!integerRegex.test($.trim($this.val()))){
										isPass = false;									
										$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
								}
							}
							break;
						case "max_length":
							var errorMsg = "输入长度请勿超过"+param;
							var byteLen = function(s) {
        						return s.replace(/[^\x00-\xff]/g, "--").length
    						};
							if(!(byteLen($.trim($this.val())) <= parseInt(param, 10))){
                                    isPass = false;
									
										$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							break;
						case "less_than":
							var errorMsg = "输入小于"+param+"的整数";
							
							if(! (parseInt($.trim($this.val())) < parseInt(param)) ){
								isPass = false;
								$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							break;
						case "equal":
							var errorMsg = "此处只能输入值为"+param;
							var decimalRegex = /^\-?[0-9]*\.?[0-9]+$/;
							
							if ($.trim($this.val()) != param) {
								isPass = false;
								$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							
							break;
						case "Lengthequal":
							var errorMsg = "此处必须输入"+param+"位";							
							var val = $.trim($this.val());
							if ( val.length != param) {
								isPass = false;
								$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							
							break;
						case "isHex":
							var errorMsg = "此处只允许输入字母和数字位";							
							var Regx = /^[A-Za-z0-9]*$/;
							if ( !Regx.test( $.trim($this.val()) )) {
								isPass = false;
								$this.addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
							}
							
							break;
						default:
							break;								
									
					}
					if(isPass == false)
						break;
				}
                   
            });

        });
        return isPass;

    };

    //绑定数据
    $.fn.tables.bindData = function (gridId, tbResult) {

        //返回结果为一个数组
       
	   var jsons = tbResult;
	   
        if (jsons == null) {
            return;
        }
        var trHtml = $("#" + gridId).find("tr").slice(1).first().html();
		$("#" + gridId).find("tbody").find("tr").remove();
		
        //遍历行结果
        for (var i = 0; i < jsons.length; i++) {
            var trnum = $("#" + gridId).find("tr").slice(1).length - 1;
            if (i > trnum) {
				if(i == 0)
                	$("#" + gridId).append("<tr name='FirstTr'>" + trHtml + "</tr>");
				else
					$("#" + gridId).append("<tr>" + trHtml + "</tr>");

            }
			//遍历行中每一列的key
			$.each($.parseJSON(jsons[i]),function(key,val){
			
					$("#" + gridId).find("tr").eq(i + 1).find("td").each(function () {
						var $child = $(this).children();
						
						if ($child.attr("name") == key || $child.attr("propertys") == key) {
							switch ($child.attr("type")) {
								case "text":
									
									$child.val(val);
									break;
								
								case "a":
								case "button":
									$child.attr("value", val);
									break;
								default:
							}
						}
					 });															   
			})
			
            
        }
    };
	//绑定数据为JSON对象
	$.fn.tables.bindObjData = function (gridId, tbResult) {

       
	   var jsons = tbResult;
        if (jsons == null) {
            return;
        }
        var trHtml = $("#" + gridId).find("tr").slice(1).first().html();
		$("#" + gridId).find("tbody").find("tr").remove();

        //遍历行结果
        for (var i = 0; i < jsons.length; i++) {
            var trnum = $("#" + gridId).find("tr").slice(1).length - 1;
            if (i > trnum) {
				if(i == 0)
                	$("#" + gridId).append("<tr name='FirstTr'>" + trHtml + "</tr>");
				else
					$("#" + gridId).append("<tr>" + trHtml + "</tr>");

            }
			//遍历行中每一列的key
			$.each(jsons[i],function(key,val){
			
					$("#" + gridId).find("tr").eq(i + 1).find("td").each(function () {
						var $child = $(this).children();
						
						if ($child.attr("name") == key || $child.attr("propertys") == key) {
							switch ($child.attr("type")) {
								case "text":									
									$child.val(val);
									break;
								
								case "a":
								case "button":
									$child.attr("value", val);
									break;
								default:
							}
							if ($child.attr("name") == "oid") {
								$child.val(val);
							}
						}
					 });															   
			})
			
            
        }
    };
    
  /**************ccy******************/ 
  //载入触发设备数据
	$.fn.tables.loadTriggerData = function (gridId, tbResult) {

       
	   var jsons = tbResult;
	   var currval;
       var curroid;
       var $oid;
        if (jsons == null) {
            return;
        }
        var trHtml = $("#" + gridId).find("tr").slice(1).first().html();
		$("#" + gridId).find("tbody").find("tr").remove();

		//对jsons数组进行倒序操作
		var newJsons = new Array();
		for (var i = 0; i < jsons.length; i++) {
			newJsons.push(jsons[jsons.length-i-1]);
		}
		jsons = newJsons;
        //遍历行结果		
        for (var i = 0; i < jsons.length; i++) {
            var trnum = $("#" + gridId).find("tr").slice(1).length - 1;
            if (i > trnum) {
				if(i == 0)
                	$("#" + gridId).append("<tr name='FirstTr' id="+(i+1)+">" + trHtml + "</tr>");
				else
					$("#" + gridId).append("<tr id="+(i+1)+">" + trHtml + "</tr>");

            }
			//遍历行中每一列的key
			$.each(jsons[i],function(key,val){			        
					$("#" + gridId).find("tr").eq(i + 1).find("td").each(function () {
						var $child = $(this).children();
						if ($child.attr("name") == key || $child.attr("propertys") == key) {							
							switch ($child.attr("type")) {
								case "text":									
									$child.val(val);
									break;
								
								case "a":
								case "button":
									$child.attr("value", val);
									break;
								default:
							}
							if ($child.attr("name") == "val") {
								currval = val;		
								$child.attr("readonly","readonly");
							}
							if ($child.attr("name") == "oid") {
								$oid = $child;
								curroid = val;
								InitOidOption(jsons[i].t_epid,$child);
							}
							if ($child.attr("name") == "t_epid") {
								var $t_epname = $child.next();
								$child.val(t_epid);
								$t_epname.attr("value",GetEtypeName(jsons[i].t_epid));	
								$t_epname.val(GetEtypeName(jsons[i].t_epid));
							}
						}
					 });															   
			});//end 遍历列
			//选择选项
			LoadOidSelect(jsons[i].t_epid, $oid, curroid, currval);
        }//end 遍历行结果
    };
	//载入联动设备配置数据
	$.fn.tables.loadReatorData = function (gridId, tbResult) {      
	   var jsons = tbResult;
	   	   
	   var currfloorid;
	   var curraid;      
       var currepid;
       var curroid;
       var currval;
       
       var $floorid;
       var $aid;
       var $e_epid;
       var $oid;          
       
        if (jsons == null) {
            return;
        }
        var trHtml = $("#" + gridId).find("tr").slice(1).first().html();
		$("#" + gridId).find("tbody").find("tr").remove();

		//对jsons数组进行倒序操作
		var newJsons = new Array();
		for (var i = 0; i < jsons.length; i++) {
			newJsons.push(jsons[jsons.length-i-1]);
		}
		jsons = newJsons;
		
        //遍历行结果
        for (var i = 0; i < jsons.length; i++) {
            var trnum = $("#" + gridId).find("tr").slice(1).length - 1;
            if (i > trnum) {
				if(i == 0)
                	$("#" + gridId).append("<tr name='FirstTr' id="+(i+1)+">" + trHtml + "</tr>");
				else
					$("#" + gridId).append("<tr id="+(i+1)+">" + trHtml + "</tr>");

            }
			//遍历行中每一列的key
			$.each(jsons[i],function(key,val){			        
					$("#" + gridId).find("tr").eq(i + 1).find("td").each(function () {
						var $child = $(this).children();
						if ($child.attr("name") == "floorid") {
							$floorid = $child;
						}
						if ($child.attr("name") == "aid") {
							$aid = $child;
						}
						if ($child.attr("name") == key || $child.attr("propertys") == key) {							
							switch ($child.attr("type")) {
								case "text":									
									$child.val(val);
									break;
								
								case "a":
								case "button":
									$child.attr("value", val);
									break;
								default:
							}
							if ($child.attr("name") == "val") {
								currval = val;		
								$child.attr("readonly","readonly");
							}
							if ($child.attr("name") == "oid") {
								$oid = $child;
								curroid = val;
								InitOidOption(jsons[i].e_epid, $child);
							}
							if ($child.attr("name") == "e_epid") {
								$e_epid = $child;
								currepid = val;
								//根据currepid获取对应的floorid、aid
								$.each(CurrElemArry,function(index,elem){				
									if (elem.epid == currepid){
									    currfloorid = elem.floorid;
									    curraid = elem.atype;
									}
								});
								InitFloorOption($floorid);
								InitAreaOption(currfloorid, $aid);
								InitEpOption(currfloorid, curraid, $child);
							}
						}
					 });															   
			});//end 遍历列
			//选择选项
			LoadFlooridSelect(currfloorid, $floorid );
			LoadAidSelect(curraid, $aid);
			LoadEpidSelect(currepid, $e_epid);
			LoadOidSelect(jsons[i].e_epid, $oid, curroid, currval);
        }//end 遍历行结果
    };
    /****************end ccy******************/
    
	//删除Trigger行 
    $.fn.tables.deleteTriggerRow = function (obj) {
        var $this = $(obj);					
		$('#ReactorAddModal').hide();
		if ($this.parents("tbody").find("tr").length < 1) {
																	   
            return false;
        }
		/*第一行删除即为清空第一行数据操作*/
		if ($this.parents("tbody").find("tr").length == 1) {
			
			
				$this.parents("tr").find("td").each(function () {
					var $child = $(this).children();
					switch ($child.attr("type")) {
									case "text":
										if($child.attr("name") == 't_epid')
											var first = true;
										else
											$child.val("");
										
										break;
									
									case "a":
									case "button":
										$child.attr("value", val);
										break;
									default:
								}
				});	
				
			return false;
		}
        $this.parents("tr").remove();
    };
	/*存储触发条件数据*/
	$.fn.tables.SetTriggerResult = function (gridId) {
		var ir = 0;
        var curepidNew;
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var curepid, curval;
            $(this).find("td").each(function () {
                var $child = $(this).children();
 				if ($child.attr("name") == 't_epid')
							curepid = $child.val();
				if ($child.attr("name") == 'val')
							curval = $child.val();
				
                
            });
			
			curepidNew = curepid;
			
			CurrElemTriggerValArry.push({"t_epid": curepid,"val": curval});
			
        });
		$.unique(CurrElemTriggerValArry);
		
		GetTriggerFrom(curepidNew);
		return false;
        
    };
	//联动触发跳转至联动内容，取出当前t_epid,val
	$.fn.tables.GetReactorFrom = function (obj) {
			var $this = $(obj);
			var curepid, curval, curoid;
			$this.parents("tr").find("td").each(function () {
					var $child = $(this).children();					
					if ($child.attr("name") == 't_epid')
						    curepid = $child.attr("value");							
					if ($child.attr("name") == 'val')
							curval = $child.val();
					if ($child.attr("name") == 'oid')
							curoid = $child.val();
			});
		$('#ReactorAddModal .input-small').removeClass("error");
		$('#ReactorAddModal .text-error').remove();
		$('#ReactorAddModal').show();
		$('#hepid').val(curepid);
		$('#hval').val(curval);
		$('#hoid').val(curoid);
		$("#ReactorAddModal_addbtn").attr("onclick","AddReactorAction('"+curepid+"','" + curval +"','" + curoid+"')");
		var cmddata = GetCurrElemReactorData(curepid, curval, curoid);
		
		if(cmddata != false) {
			InitReactorTableData(curepid, curval, cmddata);
			console.log("aaa");
		}			
		else {
			InitReactorForm();
			console.log("bbb");
		}			
	};	
	 //绑定数据
    $.fn.tables.bindSceneGroupData = function (gridId, tbResult) {

        //返回结果为一个数组
     
	   var jsons = tbResult;
	   
	   var currfloorid;
	   var curraid;      
       var currepid;
       var curroid;
       var currval;
       
       var $floorid;
       var $aid;
       var $epid;
       var $oid;  
	  
        //对jsons数组进行倒序操作
		var newJsons = new Array();
		for (var i = 0; i < jsons.length; i++) {
			newJsons.push(jsons[jsons.length-i-1]);
		}
		jsons = newJsons;
		
        if (jsons == null) {
            return;
        }
        var trHtml = $("#" + gridId).find("tr").slice(1).first().html();
		$("#" + gridId).find("tbody").find("tr").remove();
		
        //遍历行结果
        for (var i = 0; i < jsons.length; i++) {
            var trnum = $("#" + gridId).find("tr").slice(1).length - 1;
            if (i > trnum) {
				if(i == 0)
                	$("#" + gridId).append("<tr name='FirstTr'>" + trHtml + "</tr>");
				else
					$("#" + gridId).append("<tr>" + trHtml + "</tr>");

            }
			//遍历行中每一列的key
			$.each(jsons[i],function(key,val){
			
					$("#" + gridId).find("tr").eq(i + 1).find("td").each(function () {
						var $child = $(this).children();
						
						if ($child.attr("name") == "floorid") {
							$floorid = $child;
						}
						if ($child.attr("name") == "aid") {
							$aid = $child;
						}
						if ($child.attr("name") == key || $child.attr("propertys") == key) {							
							switch ($child.attr("type")) {
								case "text":									
									$child.val(val);
									break;
								
								case "a":
								case "button":
									$child.attr("value", val);
									break;
								default:
							}
							if ($child.attr("name") == "val") {
								currval = val;		
								$child.attr("readonly","readonly");
							}
							if ($child.attr("name") == "oid") {
								$oid = $child;
								curroid = val;
								InitOidOption(jsons[i].epid, $child);
							}
							if ($child.attr("name") == "epid") {
								$epid = $child;
								currepid = val;
								//根据currepid获取对应的floorid、aid
								$.each(CurrElemArry,function(index,elem){				
									if (elem.epid == currepid){
									    currfloorid = elem.floorid;
									    curraid = elem.atype;
									}
								});
								InitFloorOption($floorid);
								InitAreaOption(currfloorid, $aid);
								InitEpOption(currfloorid, curraid, $child);
							}
						}
					 });//end 遍历行														   
			});//end 遍历列
			//选择选项
			LoadFlooridSelect(currfloorid, $floorid );
			LoadAidSelect(curraid, $aid);
			LoadEpidSelect(currepid, $epid);
			LoadOidSelect(jsons[i].epid, $oid, curroid, currval);
            
        }
    };
	/*存储子场景组数据*/
	$.fn.tables.SetScenesTableResult = function (gridId) {
		var ir = '0';
		
        var curepidNew;
		var resultArray =new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var curepid, curval, curoid, curdelay;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
 				if ($child.attr("name") == 'epid')
							curepid = $child.val();
				if ($child.attr("name") == 'val')
							curval = $child.val();
				if ($child.attr("name") == 'oid')
							curoid = $child.val();
				if ($child.attr("name") == 'delay')
							curdelay = $child.val();
				
                
            });
			
			curepidNew = curepid;
			isNull += curepid + curval + curoid +curdelay;
			if(isNull == "")
				console.log("ScenesTR IS null");
			else
				resultArray.push({"epid": curepid,"oid": curoid,"val": curval,"delay": curdelay});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
			return resultArray;
        
    };
	/*存储场景组数据*/
	$.fn.tables.SetSceneGroupTableResult = function (gridId) {
		var ir = '0';
        
		var resultArray =new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var curepid, curval;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
 				if ($child.attr("name") == 'id')
							curepid = $child.val();
				if ($child.attr("name") == 'name')
							curval = $child.val();
				
                
            });
			
			isNull += curepid + curval;
			if(isNull == "")
				console.log("ScenesGroupTR IS null");
			else
				resultArray.push({"id": curepid,"name": curval,"i": ir});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
			return resultArray;
        
    };
	
	//场景类型跳转至场景内容配置
	$.fn.tables.GetSceneFrom = function (obj) {
			var $this = $(obj);
			var curscesetid = $('#curscesetid').val();
			var cursceneTypeid, cursceneTypename;
			$this.parents("tr").find("td").each(function () {
					var $child = $(this).children();					
					if ($child.attr("name") == 'id')
							cursceneTypeid = $child.val();
					if ($child.attr("name") == 'name')
							cursceneTypename = $child.val();
			});
		$('#SceneGroupAddDiv .input-small').removeClass("error");
		$('#SceneGroupAddDiv .text-error').remove();
		$('#SceneGroupAddDiv').show();
		$('#hsceneTypename').val(cursceneTypename);
		
		$("#ScenesAddModal_addbtn").attr("onclick","AddScenesAction('"+curscesetid+"','" + cursceneTypeid +"');");
		var cmddata = GetCurrScesetScenesData(curscesetid,cursceneTypeid);
		
		if(cmddata != false)
			InitScenesTableData(cursceneTypeid, cursceneTypename, cmddata);
		else
			InitScenesForm();
	};
	$.fn.tables.GetCMDTableResult = function (gridId) {
		var ir = '0';      
		var resultArray =new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var id,oid, name, dtype,val;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
				if ($child.attr("name") == 'id')
							id = $child.val();
 				if ($child.attr("name") == 'name')
							name = $child.val();
				if ($child.attr("name") == 'oid')
							oid = $child.val();
				if ($child.attr("name") == 'dtype')
							dtype = $child.val();
				if ($child.attr("name") == 'val')
							val = $child.val();
				
				
                
            });
			isNull += id + name + oid + dtype + val;
			if(isNull == "")
				console.log("CMDTR IS null");
			else
				resultArray.push({"id": id,"oid": oid,"name": name,"dtype": dtype,"val": val});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
		 	return resultArray;
        
    };
	/*获取触发条件表格数据*/
	$.fn.tables.GetTriggerAddtableResult = function (gridId) {
		 var ir = '0';    
		var resultArray =new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var t_epid,val,oid;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
                
				if ($child.attr("name") == 't_epid')
							t_epid = $child.val();
 				
				if ($child.attr("name") == 'val') 			        
				            val = $child.val();
				
				if ($child.attr("name") == 'oid')
							oid = $child.val();
                
            });
			if(val == "")
				isNull = "";
			else
				isNull += t_epid + val + oid;
			if(isNull == "")
				console.log("TriggerTR IS NULL");
			else
				resultArray.push({"t_epid": t_epid,"val": val,"oid": oid,"i": ir});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
			return resultArray;
        
    };
	/*获取联动内容表格数据*/
	$.fn.tables.GetReactorAddtableResult = function (gridId) {
		var ir = '0';     
		var resultArray =new Array();
        $("#" + gridId).find("tr").slice(1).each(function () {

            var isRepeat = false;
			var e_epid,oid,val,delay;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
				if ($child.attr("name") == 'e_epid')
							e_epid = $child.val();
				if ($child.attr("name") == 'oid')
							oid = $child.val();
 				
				if ($child.attr("name") == 'val')
							val = $child.val();	
				if ($child.attr("name") == 'delay')
							delay = $child.val();	
                
            });
			isNull += e_epid + val + oid +delay;
			if(isNull == "")
				console.log("ReactorTR IS NULL");
			else
				resultArray.push({"e_epid": e_epid,"oid": oid,"val": val,"delay": delay});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
			return resultArray;
        
    };
	/*报警器处理*/
	$.fn.tables.GetAlarmAreaTableResult = function (gridId) {
		var ir = '0';     
		var resultArray =new Array();
		console.log("chil"+gridId);
        $("#" + gridId).find("tr").slice(1).each(function () {
			console.log("isNull");
            var isRepeat = false;
			var id,name;
			var isNull = "";
            $(this).find("td").each(function () {
                var $child = $(this).children();
				console.log("this="+$child.attr("name"));
				if ($child.attr("name") == 'id'){
					console.log("childIDBB="+$child.val());
							id = $child.val();
							console.log("childID="+id);
				}
				if ($child.attr("name") == 'name'){
					console.log("childIDAA="+$child.val());
							name = $child.val();
							console.log("child NAME="+name);
				}
            });
			isNull += id + name;
			if(isNull == "")
				console.log("ReactorTR IS NULL");
			else
				resultArray.push({"id": id,"name": name});
			
        });
		$.unique(resultArray);
		if(resultArray.length == 0)
			return ir;
		else
			return resultArray;
        
    };
	 $.fn.tables.addAlarmAreaRow = function (gridId) {
		AlarmAreaidint ++;
        var tbRow = "<tr ><td><input type='text' class='input-small' validate='required|integer' name='id' id='id' readonly='true' disabled='disabled' value='"+AlarmAreaidint+"'></td><td><input type='text' class='input-small' validate='required' name='name' id='name'></td><td><a  title='删除' onClick='deleteRow(this)'><i class='icon-remove'></i></a></td></tr>";
		
		$("#" + gridId).append(tbRow);
        $("#" + gridId).find("tr").last().find("td").last().children().removeAttr("name").attr("value", "");
    };
	$.fn.tables.addAlarmAreaZoneTableRow = function (gridId) {
		AlarmZoneidint ++;
        var tbRow = "<tr ><td><input type='text' class='input-small' validate='required|integer' name='id' id='id' readonly='true' disabled='disabled' value='"+AlarmZoneidint+"'></td><td><input type='text' class='input-small' validate='required' name='name' id='name'></td><td><a  title='删除' onClick='deleteRow(this)'><i class='icon-remove'></i></a></td></tr>";
		
		$("#" + gridId).append(tbRow);
        $("#" + gridId).find("tr").last().find("td").last().children().removeAttr("name").attr("value", "");
    };
})(jQuery);